
package de.fhhof.brst.user;

import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import de.fhhof.brst.dao.HibernateEventDAO;
import de.fhhof.brst.dao.HibernateUserDAO;
import de.fhhof.brst.dao.UserDAO;
import de.fhhof.brst.data.User;
import de.fhhof.brst.session.SessionBean;
@ManagedBean
@RequestScoped
public class CustomerProfile implements Serializable {
  /**
   * 
   */
  private static final long serialVersionUID =  5380661561280785733L;

  private de.fhhof.brst.data.User user;

  private de.fhhof.brst.dao.UserDAO userDAO =  HibernateUserDAO.getHibernateUserDAO();

  private String confirmPass =  "";

  @ManagedProperty(value = "#{sessionBean}")
  private de.fhhof.brst.session.SessionBean sessionBean;

  public CustomerProfile() {
		
  }

  @PostConstruct
  public void init() {
		user = sessionBean.getUser();
  }

  public void submit() {
        FacesMessage message = new FacesMessage("Profil gespeichert!");
        
        if (!this.confirmPass.equals(this.user.getPassword())) {
			this.confirmPass = "";
			message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
					"Passwort falsch!", "Nochmal versuchen");
		} else {
			userDAO.editUser(user);
		}
        
        FacesContext.getCurrentInstance().addMessage(null, message);
  }

  public de.fhhof.brst.data.User getUser() {
		return user;
  }

  public de.fhhof.brst.session.SessionBean getSessionBean() {
		return sessionBean;
  }

  public void setSessionBean(de.fhhof.brst.session.SessionBean sessionBean) {
		this.sessionBean = sessionBean;
  }

  public void setUser(de.fhhof.brst.data.User user) {
		this.user = user;
  }

  public String getConfirmPass() {
		return confirmPass;
  }

  public void setConfirmPass(String confirmPass) {
		this.confirmPass = confirmPass;
  }

}
